<?php

/**
 * This is the model class for table "{{file_downloads}}".
 *
 * The followings are the available columns in table '{{file_downloads}}':
 * @property integer $fdID
 * @property integer $vendorID
 * @property integer $userID
 * @property string $file_title
 * @property string $file_desc
 * @property string $file_download
 * @property string $created
 * @property string $modified
 */
class FileDownloads extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return FileDownloads the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{file_downloads}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('file_title, file_desc, file_download, file_type, enable', 'required'),
			array('vendorID, userID', 'numerical', 'integerOnly'=>true),
                        array('file_download', 'file','types'=>'doc,docx, pdf', 'allowEmpty'=>true ,'on'=>'update'),
			array('file_title, file_desc, file_download', 'length', 'max'=>500),
                        array('modified','default',
                              'value'=>new CDbExpression('NOW()'),
                              'setOnEmpty'=>false,'on'=>'update'),
                       array('created,modified','default',
                             'value'=>new CDbExpression('NOW()'),
                              'setOnEmpty'=>false,'on'=>'insert'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('fdID, vendorID, userID, file_title, file_desc, file_download, created, modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'fdID' => 'Fd',
			'vendorID' => 'Vendor',
			'userID' => 'User',
			'file_title' => 'File Title',
			'file_desc' => 'File Desc',
			'file_download' => 'Document',
			'file_type' => 'File Type',
                        'enable'=>'Approve',
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('fdID',$this->fdID);
		$criteria->compare('vendorID',$this->vendorID);
		$criteria->compare('userID',$this->userID);
		$criteria->compare('file_title',$this->file_title,true);
		$criteria->compare('file_desc',$this->file_desc,true);
		$criteria->compare('file_download',$this->file_download,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
        
         public static function getList($type,$arrParams)
        {
            switch ($type)
            {
                case 'LATEST-FILES':
                return FileDownloads::model()->findAll(array('order'=>'fdID DESC','limit'=>'10'));
                break;    
            }
        }
}